import dash_ag_grid as dag
from dash import Dash, html, Input, Output, Patch, callback
import pandas as pd
import dash_bootstrap_components as dbc

app = Dash(external_stylesheets=[dbc.themes.BOOTSTRAP])

df2 = pd.read_csv('data_stac_division.csv')

width_title = 150
width_column = 120
rowHeight = 25

columnDefsStac = [
    {"field": "division", "filter": True, "sortable": True,
     "pinned": "left", "resizable": False, "width": width_title, 'rowGroup': True, 'hide': True},
    {"field": "Korpus", 'headerName': 'Отделение'},
    {
        'headerName': 'Дневной стационар',
        'children': [
            {'field': "planStac", "width": width_column, 'aggFunc': 'sum', 'headerName': 'План'},
            {'field': "factStac", 'headerName': 'Факт', "width": width_column, 'aggFunc': 'sum'},
            {'field': "percentStac", 'headerName': '%', "width": width_column},
        ]
    },
    {
        'headerName': 'Стационар на дому',
        'children': [
            {'field': "planStacHome", 'headerName': 'План', "width": width_column, 'aggFunc': 'sum'},
            {'field': "factStacHome", 'headerName': 'Факт', "width": width_column, 'aggFunc': 'sum'},
            {'field': "percentStacHome", 'headerName': '%', "width": width_column},
        ]
    }
]

app.layout = html.Div(
    [
        dbc.Alert("Стационар-замещающая помощь", color="primary", style={"margin-top": "16px"}),
        dag.AgGrid(
            id="row-pinning-bottom-2",
            enableEnterpriseModules=True,
            rowData=df2.to_dict("records"),
            columnDefs=columnDefsStac,
            defaultColDef={"editable": True},
            dashGridOptions={"animateRows": True, "rowHeight": rowHeight, "domLayout": "autoHeight"},
        ),
    ])

if __name__ == "__main__":
    app.run(debug=True)
